package com.tyrone.concurrent.concurrentUtils;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch构造器收到int类型的值作为计数器，
 * 每次调用CountDownLatch.countDown()
 *
 * @author Tyrone
 * @date 2021/12/22 14:15
 */
public class CountDownLatchTest {

    private static CountDownLatch countDownLatch = new CountDownLatch(2);

    public static void main(String[] args) throws InterruptedException{
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(1);
                countDownLatch.countDown();
//                System.out.println(2);
//                countDownLatch.countDown();
//                System.out.println(4);
//                countDownLatch.countDown();

//                ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
//                ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false,false);
//                for (ThreadInfo threadInfo : threadInfos) {
//                    String threadName = threadInfo.getThreadName();
//                    long threadId = threadInfo.getThreadId();
//                    System.out.println(threadName+":  "+threadId);
//                }
            }
        }).start();
        countDownLatch.await();
        System.out.println(3);
    }
}
